How to use daisyUI themes?
daisyUI comes with a number of themes, which you can use with no extra effort. Each theme defines a set of colors which will be used on all daisyUI elements. To use a theme, add its name in tailwind.config.js and activate it by adding data-theme attribute to HTML tag:module.exports = {
//...
daisyui: {
themes: ["light", "dark", "cupcake"],
},
}
<html data-theme="cupcake"></html>
I suggest using theme-change
, so you can switch themes and save selected theme in local storage.
module.exports = {
//...
daisyui: {
themes: [
"light",
"dark",
"cupcake",
"bumblebee",
"emerald",
"corporate",
"synthwave",
"retro",
"cyberpunk",
"valentine",
"halloween",
"garden",
"forest",
"aqua",
"lofi",
"pastel",
"fantasy",
"wireframe",
"black",
"luxury",
"dracula",
"cmyk",
"autumn",
"business",
"acid",
"lemonade",
"night",
"coffee",
"winter",
],
},
}
The default theme is light
(or dark
for dark mode) but you can change the default theme from tailwind.config.js cupcake
will be the default theme for light modedark
will be the default theme for dark modecmyk
can be applied on any HTML tag with data-theme='cmyk'
module.exports = {
daisyui: {
themes: ["cupcake", "dark", "cmyk"],
},
}
themes
config to false. module.exports = {
//...
daisyui: {
themes: false,
},
}
If you don't want to include any themes and disable all colors, set themes
config to an empty array. module.exports = {
//...
daisyui: {
themes: [],
},
}
data-theme='THEME_NAME'
to any element and everything inside will have your theme. You can nest themes and there is no limit! You can force a section of your HTML to only use a specific theme. <html data-theme="dark">
<div data-theme="light">
This div will always use light theme
<span data-theme="retro">This span will always use retro theme!</span>
</div>
</html>
tailwind.config.js
file. In the below example, I added a new theme called mytheme
and I'm also including dark
and cupcake
themes. mytheme
) will be the default theme.dark
theme will be the default theme for dark mode.primary
button). You can also add optional color names to have full control over all colors.
module.exports = {
//...
daisyui: {
themes: [
{
mytheme: {
"primary": "#a991f7",
"secondary": "#f6d860",
"accent": "#37cdbe",
"neutral": "#3d4451",
"base-100": "#ffffff",
},
},
"dark",
"cupcake",
],
},
}
module.exports = {
//...
daisyui: {
themes: [
{
mytheme: {
"primary": "#a991f7",
"secondary": "#f6d860",
"accent": "#37cdbe",
"neutral": "#3d4451",
"base-100": "#ffffff",
"--rounded-box": "1rem", // border radius rounded-box utility class, used in card and other large boxes
"--rounded-btn": "0.5rem", // border radius rounded-btn utility class, used in buttons and similar element
"--rounded-badge": "1.9rem", // border radius rounded-badge utility class, used in badges and similar
"--animation-btn": "0.25s", // duration of animation when you click on button
"--animation-input": "0.2s", // duration of animation for inputs like checkbox, toggle, radio, etc
"--btn-text-case": "uppercase", // set default text transform for buttons
"--btn-focus-scale": "0.95", // scale transform of button when you focus on it
"--border-btn": "1px", // border width of buttons
"--tab-border": "1px", // border width of tabs
"--tab-radius": "0.5rem", // border radius of tabs
},
},
],
},
}
[data-theme="mytheme"] .btn {
border-width: 2px;
border-color: black;
}
light
theme and change its primary
and primary-focus
colors: module.exports = {
//...
daisyui: {
themes: [
{
light: {
...require("daisyui/src/theming/themes")["[data-theme=light]"],
"primary": "blue",
"primary-focus": "mediumblue",
},
},
],
},
}
module.exports = {
//...
daisyui: {
themes: [
{
light: {
...require("daisyui/src/theming/themes")["[data-theme=light]"],
".btn-twitter": {
"background-color": "#1EA1F1",
"border-color": "#1EA1F1",
},
".btn-twitter:hover": {
"background-color": "#1C96E1",
"border-color": "#1C96E1",
},
},
},
],
},
}